package com.example.config;


import com.example.sys.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;

@Slf4j
//@Component
public class BaseUserDetailsService implements UserDetailsService {

    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private PasswordEncoder passwordEncoder;

    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        String passwd = sysUserService.getByUserName(username).getPassword();
        log.error("收到的账号:"+username+",查到的密码:"+passwd);
        return new User(username, passwordEncoder.encode(passwd),
                true,true,true,true,
                AuthorityUtils.commaSeparatedStringToAuthorityList("user,ROLE_CLIENT"));
    }
}
